package edu.ustb.efws.base.controller;

import edu.ustb.efws.base.domain.Sms;
import edu.ustb.efws.base.service.SmsService;
import edu.ustb.efws.controller.vo.ResultPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信管理API
 *
 * @author TS Group
 */
@RestController
@RequestMapping("/manage/sms")
@Api(value = "/manage/sms", tags = "短信管理")
public class SmsController {
    private final SmsService service;

    @Autowired
    public SmsController(SmsService service) {
        this.service = service;
    }

    @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation("查询短信")
    public ResultPageVo<Sms> query(
            @ApiParam(value = "电话") @RequestParam(required = false) String mobile,
            @ApiParam(value = "空间位置") @RequestParam(required = false) String area,
            @ApiParam(value = "点位置") @RequestParam(required = false) String position,
            @RequestParam(defaultValue = "true") @ApiParam(value = "是否查询记录数") Boolean isCount,
            @RequestParam(defaultValue = "0") @ApiParam(value = "查询页数") int page,
            @RequestParam(defaultValue = "15") @ApiParam(value = "查询每页记录数") int rows){

        return new ResultPageVo
                .Builder<>(page, rows, service.query(mobile, area, position,page * rows, rows))
                .count(isCount, () -> service.count(mobile, area, position))
                .build();
    }
}
